Replace info component check for externalDocs to use externalDocsUrl #6981
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change modifies the logic check for displaying the external documentation link in the
Info
component to now check theexternalDocsUrl
variable instead of theexternalDocs
variable.Motivation and Context
Fixes #6975
This change is necessary to prevent the rendering of the
Link
component when there is no external documentation link provided. This is causing an accessibility issue as links are being rendered without associated URLs.Currently,
externalDocs
is checked here, so ifexternalDocs
is truthy, then theLink
component is rendered. However,externalDocs
is always a truthy value. This is because even whenexternalDocs
is not defined in the given API object, it is assignednew Map()
here, which is a truthy value. My solution is to checkexternalDocsUrl
instead, which is already pulled fromexternalDocs
, as this is the actual value being displayed in theLink
component.Previously,
externalDocsUrl
was used here instead ofexternalDocs
. From what I can tell, the change was made here, but I am not sure if there was a specific reason for changing this logic. I see no issue in returning to checkingexternalDocsUrl
as this is a variable already being assigned and the primary subject of the renderedLink
component.How Has This Been Tested?
This was identified and tested using our implementation in the Department of Veteran Affair's developer portal repository. We were upgrading our version of
swagger-ui
to the latest and noticed failing accessibility tests due to links being rendered without URLs in places where noexternalDocs
object was provided in the API object. Conversely, in places where theexternalDocs
object was provided, the link was rendered as expected.Without our accessibility tests, we wouldn't have been able to identify this issue because links were visually being shown when provided and not shown when not provided. The issue was, as explained, that the
Link
object was still being rendered even when no link was provided, which causes issues with screen readers.Checklist
My PR contains...
src/
is unmodified: changes to documentation, CI, metadata, etc.)package.json
)My changes...
Documentation
Automated tests